package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.AdvertiseTypeService;
import com.junzhiit.nengji.cms.web.vo.AdvertiseTypeAddVO;
import com.junzhiit.nengji.cms.web.vo.AdvertiseTypeEditVO;
import com.junzhiit.nengji.cms.web.vo.AdvertiseTypeVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/advertise/type")
public class AdvertiseTypeController extends BaseController {

	@Autowired
	private AdvertiseTypeService advertiseTypeService;

	@ApiOperation(value = "获取所有广告类型列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, AdvertiseTypeVO advertiseTypeVO) {
		return advertiseTypeService.findAll(dtp, advertiseTypeVO);
	}

	@ApiOperation(value = "根据ID查询广告类型")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseTypeService.findById(id);
	}

	@ApiOperation(value = "创建广告类型")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(AdvertiseTypeAddVO advertiseTypeAddVO) {
		AssertUtil.notBlank(advertiseTypeAddVO.getName(), "name is required.");
		return advertiseTypeService.add(advertiseTypeAddVO);
	}

	@ApiOperation(value = "修改广告类型")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(AdvertiseTypeEditVO advertiseTypeEditVO) {
		AssertUtil.notBlank(advertiseTypeEditVO.getName(), "name is required.");
		return advertiseTypeService.edit(advertiseTypeEditVO);
	}

	@ApiOperation(value = "删除广告类型")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseTypeService.delete(id);
	}

	@ApiOperation(value = "查询广告分类下拉框")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ResultVO getList() {
		return advertiseTypeService.getList();
	}
}
